#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
#define Fi(s) freopen(s,"r",stdin)
#define Fo(s) freopen(s,"w",stdout)
#define Fre(s) Fi(s".in"),Fo(s".out")
bool Mst;
const int N=100010,M=110,C=16,inf=1e9;
int n,deg[N],f[N][C+1],dep[N],fd[N];
ll ans;
vector<int> e[N],ie[N],fe[N],xe[N];
int lca(int x,int y){
	int xx,yy;
	if(dep[x]<dep[y]) swap(x,y);
	per(i,C,0){
		xx=f[x][i];
		if(dep[xx]>=dep[y]) x=xx;
	}
	if(x==y) return x;
	per(i,C,0){
		xx=f[x][i];
		yy=f[y][i];
		if(xx!=yy) x=xx,y=yy;
	}
	return f[x][0];
}
void topo(){
	queue<int> q;
	q.emplace(1);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		if(x==1){
			dep[1]=1;
		}else{
			int y=ie[x].front();
			for(int i:ie[x]){
				y=lca(i,y);
			}
			f[x][0]=y;
			dep[x]=dep[y]+1;
			fe[y].emplace_back(x);
			rep(i,1,C) f[x][i]=f[f[x][i-1]][i-1];
		}
		for(int i:e[x]){
			deg[i]--;
			if(!deg[i]) q.push(i);
		}
	}
}
int dfn[N],nfd[N],sz[N],pos[M],m=0,tim=0,ft[N];
bool to[M][M],vis[N],tp[M][M][M];
vector<pair<int,int>> E;
void dfs(int x){
	dfn[x]=++tim;
	nfd[tim]=x;
	sz[x]=1;
	vis[x]=true;
	for(int i:e[x])
		if(!vis[i]){
			ft[i]=x;
			dfs(i);
			sz[x]+=sz[i];
		}else{
			pos[++m]=i;
			pos[++m]=x;
			E.emplace_back(x,i);
		}
}
bool cmp(int x,int y){ return dfn[x]<dfn[y]; }
bool eq(int x,int y){ return dfn[x]==dfn[y]; }
int nxt[N],fy[N];
bool can(int x,int y){
	return tp[nxt[dfn[x]]][nxt[dfn[x]+sz[x]]-1][fy[y]]
		|| (dfn[x]<=dfn[y] && dfn[y]<dfn[x]+sz[x]);
}
void qwq(int x,int y,int&xx,int&yy){
	int res;
	res=1;
	per(i,C,0){
		int tmp=f[x][i];
		if(tmp && !can(tmp,y)) x=tmp,res+=1<<i;
	}
	ckmn(xx,res);
	res=1;
	per(i,C,0){
		int tmp=f[y][i];
		if(tmp && !can(tmp,x)) y=tmp,res+=1<<i;
	}
	ckmn(yy,res);
}
void slv(vector<int> v){
	int x=siz(v);
	rep(i,0,x-1) rep(j,0,x-1) if(i!=j && can(v[i],v[j])) return ;
	vector<int> len(x);
	rep(i,0,x-1) len[i]=dep[v[i]];
	rep(i,0,x-1) rep(j,i+1,x-1) qwq(v[i],v[j],len[i],len[j]);
	ll res=1;
	rep(i,0,x-1) res*=len[i];
	ans+=res;
}
void fds(int x){
	fd[x]=++tim;
	// for(int i:fe[x]) cout<<x<<"->"<<i<<"\n";
	for(int i:fe[x]) fds(i);
}
bool fcmp(int x,int y){ return fd[x]<fd[y]; }
bool feq(int x,int y){ return fd[x]==fd[y]; }
void show(int x){
	for(int i:xe[x]) cout<<x<<"->"<<i<<"\n";
	for(int i:xe[x]) show(i);
}
bool bel[N];
bool Med;
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
#ifdef SuperAnton
	cerr<<(&Mst-&Med)/1048576.<<"MB\n";
#endif
	Fre("lodge");
	int T,TT;
	cin>>n>>T>>TT;
	while(T--){
		int x,y;cin>>x>>y;
		e[x].emplace_back(y);
	}
	rep(i,1,n) for(int j:e[i]) deg[j]++,ie[j].emplace_back(i);
	topo();
	dfs(1);
	sort(pos+1,pos+1+m,cmp);
	m=unique(pos+1,pos+1+m,eq)-pos-1;
	// rep(i,1,m) cout<<pos[i]<<"!\n"[i==i_];
	// for(auto[x,y]:E) cout<<x<<"->"<<y<<"\n";
	for(auto[x,y]:E)
		to[lower_bound(pos+1,pos+1+m,x,cmp)-pos]
		  [lower_bound(pos+1,pos+1+m,y,cmp)-pos]=true;
	rep(i,1,m) rep(j,i,m){
		int x=pos[i],y=pos[j];
		if(dfn[y]>=dfn[x]+sz[x]) break;
		to[i][j]=true;
	}
	rep(k,1,m) rep(i,1,m) rep(j,1,m) to[i][j]|=to[i][k]&to[k][j];
	rep(i,1,m) fy[pos[i]]=i;
	rep(i,1,n){
		int x=nfd[i];
		if(!fy[x]) fy[x]=fy[ft[x]];
	}
	rep(l,1,m) rep(r,l,m) rep(i,1,m){
		tp[l][r][i]=tp[l][r][fy[i]]||tp[l][r-1][i]||to[r][i];
	}
	rep(i,1,m) nxt[dfn[pos[i]]]=i;
	nxt[n+1]=m+1;
	per(i,n,1) if(!nxt[i]) nxt[i]=nxt[i+1];
	// rep(i,1,m) rep(j,1,m) cout<<can(i,j)<<" \n"[j==j_];
	tim=0;
	fds(1);
	while(TT--){
		ans=0;
		int x,y;
		cin>>x>>y;
		vector<int> v(y);
		for(auto&i:v) cin>>i,bel[i]=true;
		sort(all(v),fcmp);
		rep(i,0,y-2) v.emplace_back(lca(v[i],v[i+1]));
		sort(all(v),fcmp);
		v.erase(unique(all(v),feq),v.end());
		y=siz(v);
		int rt=v.front();
		rep(i,1,y-1) xe[lca(v[i],v[i-1])].emplace_back(v[i]);
		// show(rt);
		if(x==1){
			slv({rt});
		}else if(!bel[rt]){
			if(x==2){
				if(siz(xe[rt])==2){
					slv({xe[rt][0],xe[rt][1]});
				}
			}else if(x==3){
				if(siz(xe[rt])==3){
					slv({xe[rt][0],xe[rt][1],xe[rt][2]});
				}else if(siz(xe[rt])==2){
					int A=xe[rt][0],B=xe[rt][1];
					rep(_,0,1){
						if(!bel[A] && siz(xe[A])==2){
							slv({xe[A][0],xe[A][1],B});
						}
						swap(A,B);
					}
				}
			}else if(x==4){
				if(siz(xe[rt])==4){
					slv({xe[rt][0],xe[rt][1],xe[rt][2],xe[rt][3]});
				}else if(siz(xe[rt])==3){
					int A=xe[rt][0],B=xe[rt][1],C=xe[rt][2];
					rep(_,0,2){
						if(!bel[A] && siz(xe[A])==2){
							slv({xe[A][0],xe[A][1],B,C});
						}
						swap(A,B);
						swap(B,C);
					}
				}else if(siz(xe[rt])==2){
					int A=xe[rt][0],B=xe[rt][1];
					if(!bel[A] && siz(xe[A])==2){
						if(!bel[B] && siz(xe[B])==2){
							slv({xe[A][0],xe[A][1],xe[B][0],xe[B][1]});
						}
					}
					rep(_,0,1){
						if(!bel[A]){
							if(siz(xe[A])==3){
								slv({xe[A][0],xe[A][1],xe[A][2],B});
							}else if(siz(xe[A])==2){
								int C=xe[A][0],D=xe[A][1];
								rep(o_,0,1){
									if(!bel[C] && siz(xe[C])==2){
										slv({xe[C][0],xe[C][1],D,B});
									}
									swap(C,D);
								}
							}
						}
						swap(A,B);
					}
				}
			}
		}
		for(int i:v) xe[i].clear(),bel[i]=false;
		cout<<ans<<"\n";
	}
return 0;}
/*
*/